package demo.mq.rabbit;

import java.io.IOException;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class RabbitMqMonitor {

    private static Logger logger = LoggerFactory.getLogger(RabbitMqMonitor.class);

    public static String url = "http://uat-sh-bs-3-b6-rabbitmq-0-30:15672";
    public static String user = "guest";
    public static String pass = "guest";

    public static RabbitMqManagement management = new RabbitMqManagement(url, user, pass);

    public static String queueName = "business.marketing.promotion.groupon.changed.app-msg.ttl.queue";

    @Test
    public void queueBindings() {
        JSONArray response = null;
        try {
            response = management.queueBindings(queueName);
            logger.info("response = {}", response);
        } catch (IOException e) {
            logger.error("", e);
        }
        if (response == null) {
            return;
        }
        response.stream().forEach(e -> logger.info(e.toString()));
    }

    @Test
    public void queuesBy() {
        JSONObject response = null;
        try {
            response = management.queuesBy(queueName, 120, 60, 120, 60);
            logger.info("response = {}", response);
        } catch (IOException e) {
            logger.error("", e);
        }
        if (response == null) {
            return;
        }
        logger.info("json = {}", response);
    }

    /**
     * 查找队列消费情况
     */
    @Test
    public void queues() {
        JSONArray response = null;
        try {
            response = management.queues();
        } catch (IOException e) {
            logger.error("", e);
        }
        if (response == null) {
            return;
        }
        response.stream().forEach(e -> logger.info(e.toString()));
    }

}
